package com.muyu.product.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.product.domain.ProjectInfo;
import com.muyu.product.domain.req.ProjectInfoQueryReq;
import com.muyu.product.domain.req.ProjectInfoSaveReq;
import com.muyu.product.domain.req.ProjectInfoEditReq;
import com.muyu.product.service.ProjectInfoService;
import com.muyu.common.core.web.page.TableDataInfo;

/**
 * 商品信息Controller
 *
 * @author DongZeLiang
 * @date 2024-02-27
 */
@Api(tags = "商品信息")
@RestController
@RequestMapping("/info")
public class ProjectInfoController extends BaseController {
    @Autowired
    private ProjectInfoService projectInfoService;

    /**
     * 查询商品信息列表
     */
    @ApiOperation("获取商品信息列表")
    @RequiresPermissions("product:info:list")
    @GetMapping("/list")
    public Result<TableDataInfo<ProjectInfo>> list(ProjectInfoQueryReq projectInfoQueryReq) {
        startPage();
        List<ProjectInfo> list = projectInfoService.list(ProjectInfo.queryBuild(projectInfoQueryReq));
        return getDataTable(list);
    }

    /**
     * 导出商品信息列表
     */
    @ApiOperation("导出商品信息列表")
    @RequiresPermissions("product:info:export")
    @Log(title = "商品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectInfo projectInfo) {
        List<ProjectInfo> list = projectInfoService.list(projectInfo);
        ExcelUtil<ProjectInfo> util = new ExcelUtil<ProjectInfo>(ProjectInfo.class);
        util.exportExcel(response, list, "商品信息数据");
    }

    /**
     * 获取商品信息详细信息
     */
    @ApiOperation("获取商品信息详细信息")
    @RequiresPermissions("product:info:query")
    @GetMapping(value = "/{id}")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
    public Result<ProjectInfo> getInfo(@PathVariable("id") Long id) {
        return Result.success(projectInfoService.getById(id));
    }

    /**
     * 新增商品信息
     */
    @RequiresPermissions("product:info:add")
    @Log(title = "商品信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增商品信息")
    public Result<String> add(@RequestBody ProjectInfoSaveReq projectInfoSaveReq) {
        return toAjax(projectInfoService.save(projectInfoSaveReq));
    }

    /**
     * 修改商品信息
     */
    @RequiresPermissions("product:info:edit")
    @Log(title = "商品信息", businessType = BusinessType.UPDATE)
    @PutMapping("/{id}")
    @ApiOperation("修改商品信息")
    public Result<String> edit(@PathVariable Long id, @RequestBody ProjectInfoEditReq projectInfoEditReq) {
        return toAjax(projectInfoService.updateById(ProjectInfo.editBuild(id,projectInfoEditReq)));
    }

    /**
     * 删除商品信息
     */
    @RequiresPermissions("product:info:remove")
    @Log(title = "商品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除商品信息")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
    public Result<String> remove(@PathVariable List<Long> ids) {
        return toAjax(projectInfoService.removeBatchByIds(ids));
    }
}
